#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
# @Time    : 2022/2/9 14:00
# @Author  : daguo
# @File    : match_2.py
# @Function: 
"""
import time

import execjs
import requests

url = "https://match.yuanrenxue.com/api/match/2"
with open("js_2.js", "r", encoding="utf-8")as f:
    q = f.read()
item = []
sum = 0
for i in range(1, 6):
    sign = execjs.compile(q)
    m=sign.call("f").split("=")
    params = {
        "page": i
    }
    headers = {
        "user-agent": "yuanrenxue.project",
        "Cookie": f"sessionid=3t9ejplaj0q09i3qrcsc1kwe41u5h302;m={m[1]}",
        "Referer": "https://match.yuanrenxue.com/match/2",
        "Host": "match.yuanrenxue.com"
    }
    res = requests.get(url=url, headers=headers, params=params)
    if res.status_code == 200:
        print(res.url)
        data_json = res.json().get("data")
        for i in data_json:
            value = i.get("value")
            print(f"当前数值为{value}")
            sum += value
    else:
        print("请求失败")
    time.sleep(0.75)
print(f"总和为{sum}")
